home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / Macintosh Tracker Source / Tracker Client Folder / Core 18⁄March⁄1994 / Object Access Code / ClassDeleteInd.c next >
Encoding:
C/C++ Source or Header  |  1993-05-07  |  2.5 KB  |  196 lines  |  [TEXT/KAHL]

  1. #define INDIRECT
  2.  
  3. /*
  4.  *  delete.c - destroy an object
  5.  *
  6.  *  Copyright (c) 1991 Symantec Corporation.  All rights reserved.
  7.  *
  8.  */
  9.  
  10. #define OOPS_PRIVATE
  11. #include "oops.h"
  12.  
  13. #ifdef INDIRECT
  14.     #define __delete __delete_indirect
  15. #else
  16.     #define __delete __delete_direct
  17. #endif
  18.  
  19. extern void __delete(...);
  20.  
  21.  
  22.  
  23. #ifdef MEMDEBUG
  24. /* some extra debugging code */
  25.  
  26. #include "Memory.h"
  27.  
  28. static void MyTestFunc(void);
  29.  
  30. static void* messagetestfuncptr = MyTestFunc;
  31.  
  32. static void MyTestFunc(void)
  33.     {
  34.         void*            Temp;
  35.  
  36.         asm
  37.             {
  38.                 move.l        d0,Temp
  39.             }
  40.         CheckHandleExistence((Handle)Temp);
  41.     }
  42. #endif
  43.  
  44.  
  45. /*
  46.  *  __delete - destroy an object
  47.  *
  48.  *  The compiler, for
  49.  *
  50.  *        delete obj;
  51.  *
  52.  *  generates:
  53.  *
  54.  *            MOVE.L    obj,-(SP)
  55.  *            JSR        __delete
  56.  *            ADDQ.L    #4,SP
  57.  *
  58.  *  This routine calls the destructors for the class and each of its superclasses
  59.  *  in turn, root class last, then deallocates the object, calling an appropriate
  60.  *  "operator delete" method if available.
  61.  *
  62.  */
  63.  
  64. void
  65. __delete()
  66. {
  67.     asm {
  68.         link    a6,#0
  69.         movem.l    d5/d6/d7/a2,-(sp)
  70.         moveq    #0,d5                ;  D5 = deallocator Ref (unknown)
  71.  
  72. ;;
  73. ;
  74. ;  set D7 = object
  75. ;  set D6 = class Ref
  76. ;
  77. ;;
  78.  
  79.         move.l    8(a6),d7
  80.         beq.s    @5                    ;  object is 0
  81. #ifdef MEMDEBUG
  82.         movem.l    d0/a0,-(sp)
  83.         move.l    d7,d0  ;copy object over to be inspected
  84.         move.l    messagetestfuncptr,a0
  85.         jsr        (a0)
  86.         movem.l    (sp)+,d0/a0
  87. #endif
  88.         movea.l    d7,a0
  89.     #ifdef INDIRECT
  90.         movea.l    (a0),a0
  91.     #endif
  92.         move._    (a0),d6
  93.  
  94. ;;
  95. ;
  96. ;  set A2 ==> class info
  97. ;
  98. ;;
  99.  
  100. @1        movea._    d6,a2
  101.     #ifdef BASE_REG
  102.         adda.l    BASE_REG,a2
  103.     #endif
  104.         moveq    #1,d0
  105.         add.w    (a2)+,d0
  106.         lsl.w    #DSHIFT,d0
  107.         adda.w    d0,a2
  108.  
  109. ;;
  110. ;
  111. ;  determine deallocator to use
  112. ;
  113. ;;
  114.  
  115.         tst._    d5
  116.         bne.s    @2                    ;  already have one
  117.         move._    ClassInfo_(deallocator)(a2),d5
  118.  
  119. ;;
  120. ;
  121. ;  set class Ref in object
  122. ;
  123. ;;
  124.  
  125. @2        movea.l    d7,a0
  126.     #ifdef INDIRECT
  127.         movea.l    (a0),a0
  128.     #endif
  129.         move._    d6,(a0)
  130.  
  131. ;;
  132. ;
  133. ;  call destructor
  134. ;
  135. ;;
  136.  
  137.         move._    ClassInfo_(destructor)(a2),d1
  138.         beq.s    @3                    ;  class has no destructor
  139. ;
  140.         movea._    d1,a0
  141.     #ifdef BASE_REG
  142.         adda.l    BASE_REG,a0
  143.     #endif
  144.         move.l    d7,-(sp)
  145.         jsr        (a0)
  146.  
  147. ;;
  148. ;
  149. ;  advance to superclass
  150. ;
  151. ;;
  152.  
  153. @3        move._    ClassInfo_(superclass)(a2),d6
  154.         bne.s    @1
  155.  
  156. ;;
  157. ;
  158. ;  deallocate object using "operator delete" from appropriate class
  159. ;
  160. ;;
  161.  
  162.         tst._    d5
  163.         beq.s    @4                    ;  no deallocator
  164. ;
  165.         movea._    d5,a0
  166.     #ifdef BASE_REG
  167.         adda.l    BASE_REG,a0
  168.     #endif
  169.         move.l    d7,-(sp)
  170.         jsr        (a0)
  171.         bra.s    @5
  172.  
  173. ;;
  174. ;
  175. ;  deallocate object using default deallocator
  176. ;
  177. ;;
  178.  
  179. @4        movea.l    d7,a0
  180.     #ifdef INDIRECT
  181.         _DisposHandle
  182.     #else
  183.         _DisposPtr
  184.     #endif
  185.  
  186. ;;
  187. ;
  188. ;  done
  189. ;
  190. ;;
  191.  
  192. @5        movem.l    -16(a6),d5/d6/d7/a2
  193.         unlk    a6
  194.     }
  195. }
  196.